const mongoose = require('mongoose');
const { dbUrl } = require('../config')

mongoose.connect(dbUrl, { useNewUrlParser: true, useUnifiedTopology: true });

const db = mongoose.connection;

// 数据库连接失败
db.on('error', console.error.bind(console, 'connection error:'));

// 数据库连接成功
db.once('open', function () {
    console.log('connection is ok');
});

// 导出模型
module.exports = {
    User: mongoose.model('users', require('./user'))
}